package com.cloudOffice.service.Impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cloudOffice.mapper.OaProcessTypeMapper;
import com.cloudOffice.model.process.ProcessTemplate;
import com.cloudOffice.model.process.ProcessType;
import com.cloudOffice.service.OaProcessTemplateService;
import com.cloudOffice.service.OaProcessTypeService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 审批类型
 */
@Service
public class OaProcessTypeServiceImpl extends ServiceImpl<OaProcessTypeMapper, ProcessType> implements OaProcessTypeService {
	
	@Resource
	private OaProcessTemplateService processTemplateService;
	
	//查询所有审批分类和每个分类所有审批模板
	@Override
	public List<ProcessType> findProcessType() {
		// 查询所有审批分类，返回list集合
		List<ProcessType> processTypeList = baseMapper.selectList(null);
		// 遍历返回所有审批分类list集合
		for (ProcessType processType : processTypeList) {
			// 根据审批分类id查询对应审批模板
			List<ProcessTemplate> processTemplateList =
					processTemplateService.list(Wrappers.<ProcessTemplate>lambdaQuery().eq(ProcessTemplate::getProcessTypeId,
							processType.getId()));
			
			// 根据审批分类id查询对应审批模板数据（List）封装到每个审批分类对象里面
			processType.setProcessTemplateList(processTemplateList);
		}
		return processTypeList;
	}
}
